<html>
  <head>
    <style type="text/css">
       body  {
		background-color: black;
	}
       
    </style>
    <script>
    System.Gadget.settingsUI = "Settings.html";
    
    var gLineArray = new Array();
    var gSleep = 2 * 1000;
    
	function ReadFile()
	{
		var fsoDir = new ActiveXObject("Scripting.FileSystemObject");
		var oDir = fsoDir.GetFolder(System.Gadget.path + "\\UserData\\");
		var it = new Enumerator(oDir.files);
		var fileArray = new Array();
		for (i=0; !it.atEnd(); it.moveNext())
		{
			fileArray[i++] = it.item();
		}
		
		var index = getRand(fileArray.length);
		var randomFile = fileArray[index];
		
		var fso = new ActiveXObject("Scripting.FileSystemObject");
		var file = fso.GetFile(randomFile);
		var ForReading = 1;
		var f = fso.OpenTextFile(randomFile, ForReading);
		var body = f.Read(file.Size);
		
		f.Close();
		
		var lineArray = new Array();
		// gLineArray = body.split("\n");
		lineArray = body.split("\n");
		gLineArray = RemoveBlankLine(lineArray);
	}
	
	function trim(stringToTrim)
	{
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
	
	String.prototype.trim = function() {return this.replace(/^\s+|\s+$/g,"");}
	
	function RemoveBlankLine(lineArray)
	{
		var newArray = new Array();
		for (i=0,j=0; i<lineArray.length; ++i)
		{
			if (lineArray[i].trim() != '')
				newArray[j++] = lineArray[i];
		}
		
		return newArray;
	}
	
	function ReLoad()
	{
		ReadFile();
		init();
		
		setTimeout("ReLoad()", 60 * 1000);
	}
	
	function getRand(max)
	{
		var rnd = Math.floor(Math.random() * (max + 1));
		if (rnd == max)
			rnd--;
		if (rnd < 0)
			rnd = 0;
			
		return rnd;
	}
	
	function init()
	{
		var sleep = System.Gadget.Settings.read("Sleep");
		if (sleep != "")
			gSleep = sleep * 1000;
	}
	
	function SlideShow()
	{
		var rowNum = gLineArray.length;
		var index = getRand(rowNum);
		
		document.getElementById('klok').innerHTML = gLineArray[index];
		
		setTimeout("SlideShow()", gSleep);
	}
	</script>
	</head>
	
	<body onload="ReLoad() & SlideShow();" style="width:450px;height:90px;">
	<g:background src="img/background.png" style="position:absolute;top:0px;left:0px; width:450px;height:90px">
	<div id="klok" style="font-family:tahoma;font-size:12px; font-weight:bold; color:silver;position:absolute;top:20px;left:20px;width:410px;">
	</div>
	</body>
</html>